package com.tbs.parkingsaleapp.Http.Listenner;

import abstergo.tbs.betterasyc.AsycBase.IAsycBackgroundAction;
import abstergo.tbs.betterasyc.AsycBase.IAsycResultAction;
import android.content.Context;
import android.widget.Toast;
import com.tbs.parkingsaleapp.Http.HttpHelper;
import com.tbs.parkingsaleapp.Http.JsonData.OrderInfo;
import com.tbs.parkingsaleapp.SystemManager.NetWorkSetting;
import com.tbs.parkingsaleapp.UI.Adapters.OrderAdapter;

public class PayHttper implements IAsycBackgroundAction<Integer,Integer>, IAsycResultAction<Integer> {
    @Override
    public Integer BackGroundAction(Integer... params) throws Exception {
        String r= HttpHelper.Get(NetWorkSetting.PayUrl(params[0])).trim();
        return Integer.valueOf(r);
    }
    Context context;
    OrderInfo info;

    public PayHttper(Context context,OrderInfo info)
    {
        this.context=context;
        this.info=info;
    }

    @Override
    public void ResultFunction(Integer result) {
        switch (result)
        {
            case 0:
                Toast.makeText(context,"订单不存在",Toast.LENGTH_SHORT).show();
                break;
            case 1:
                Toast.makeText(context,"购买成功",Toast.LENGTH_SHORT).show();
                info.getBasic().setStatus(1);
                OrderAdapter.UpdateItem(info);
                break;
            case 2:
                Toast.makeText(context,"订单错误，请检查订单和车位状态",Toast.LENGTH_SHORT).show();
                break;
            case 3:
                Toast.makeText(context,"车位信息不存在",Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
